import 'dart:collection';

import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_nft/provider/LoginProvider.dart';
import 'package:provider/provider.dart';
import 'package:tobias/tobias.dart' as tobias;

import '../../../api/API.dart';
class ProductNew {
  late int id;
  late String productCode;
  late String productTitle;
  late String productImage;
  late String productDesc;
  late int initPrice;
  late int newPrice;
  late int productCount;
  late int productStock;
  late int orgAuthId;
  late String createTime;
  late String updateTime;
  late String productTime;
  late int dFlag;

  static ProductNew? fromMap(Map<String, dynamic> map) {
    if (map == null) return null;
    ProductNew productNewBean = ProductNew();
    productNewBean.id = map['id'];
    productNewBean.productCode = map['productCode'];
    productNewBean.productTitle = map['productTitle'];
    productNewBean.productImage = map['productImage'];
    productNewBean.productDesc = map['productDesc'];
    productNewBean.initPrice = map['initPrice'];
    productNewBean.newPrice = map['newPrice'];
    productNewBean.productCount = map['productCount'];
    productNewBean.productStock = map['productStock'];
    productNewBean.orgAuthId = map['orgAuthId'];
    productNewBean.createTime = map['createTime'];
    productNewBean.updateTime = map['updateTime'];
    productNewBean.productTime = map['productTime'];
    productNewBean.dFlag = map['dFlag'];
    return productNewBean;
  }

  Map toJson() => {
    "id": id,
    "productCode": productCode,
    "productTitle": productTitle,
    "productImage": productImage,
    "productDesc": productDesc,
    "initPrice": initPrice,
    "newPrice": newPrice,
    "productCount": productCount,
    "productStock": productStock,
    "orgAuthId": orgAuthId,
    "createTime": createTime,
    "updateTime": updateTime,
    "productTime": productTime,
    "dFlag": dFlag,
  };
}
class PayProductDetail extends StatefulWidget {
  @override
  _PayProductDetailState createState() => _PayProductDetailState();
}

class _PayProductDetailState extends State<PayProductDetail> {

  late List<ProductNew> productNewList;

  late ProductNew productNew;

  String threeMax = "";

  late Map toMap = new HashMap();

  String productCode = "";

  String content = "3D商品为虚拟3D商品,而非实物,仅限实名认证为年满18周岁的中国大陆用户购买. 3D商品的版权由发行方或原创者拥有,除另行取得版权拥有者书面同意外,用户不得将3D商品用于任何商业用途. 本商品已经售出,不支持退换.本商品源文件不支持本地下载. 请勿对3D商品进行炒作,场外交易,欺诈,或以任何其他非法方式进行使用.";

  String orgUrl = "";

  String mylUrl = "";

  getBannerList()async{
    var request = await new Dio().get(API.reqUrl+"/get/banner/list");
    setState(() {
      orgUrl = request.data["dataObj"][2]["bannerUrl"].toString();
      mylUrl = request.data["dataObj"][3]["bannerUrl"].toString();
    });

  }

  @override
  void initState() {
    getBannerList();
    // TODO: implement initState
    super.initState();
    _getnew();
    _getthreemax();
  }

  void _getthreemax()async{
    print("get请求");
    var result = await Dio().get(API.reqUrl+"/get/threemax/detail/"+context.read<LoginProvider>().getProductDetailCode());

    print("打印连接..................");
    print(result.data["dataObj"]["threeMaxUrl"]);
    context.read<LoginProvider>().setProductMaxUrl(result.data["dataObj"]["threeMaxUrl"]);
  }

  void _getnew() async {
    print("get请求");
    var result =
    await Dio().get(API.reqUrl+"/api/GxProduct/get/code/"+context.read<LoginProvider>().getProductDetailCode());
    print(result);
    print("打印对象详情");
    setState(() {
      toMap = result.data['dataObj'];
    });
    print(result);
  }



  @override
  Widget build(BuildContext context) {

    Object? teacherMap = ModalRoute.of(context)!.settings.arguments;
    print("传来的参数"+teacherMap.toString());

    setState(() {
      productCode = teacherMap.toString();
    });

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Color.fromRGBO(43, 43, 43, 1),
        elevation: 0,
        leading: InkWell(
          onTap: () {
            Navigator.of(context).pop();
          },
          child: Icon(
            Icons.arrow_back,
          ),
        ),
        //title: Text("3d效果展示"),
      ),
      body: Container(
        height: MediaQuery.of(context).size.height,
        width: MediaQuery.of(context).size.width,
        color: Color.fromRGBO(43, 43, 43, 1),
        child: Stack(
          children: [
            ListView(
              children: [
                Padding(
                  padding: EdgeInsets.only(left: 4, right: 4),
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(18),
                      color: Color.fromRGBO(60, 63, 65, 1),
                    ),
                    width: MediaQuery.of(context).size.width,
                    height: 60,
                    child: Padding(
                      padding: EdgeInsets.only(left: 15, right: 15),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Container(
                                width: 40,
                                height: 40,
                                decoration: BoxDecoration(
                                    border: Border.all(
                                        width: 1, color: Colors.white),
                                    borderRadius: BorderRadius.circular(40),
                                    image: DecorationImage(
                                        image: NetworkImage(
                                            orgUrl),
                                        fit: BoxFit.fill)),
                              ),
                              SizedBox(
                                width: 8,
                              ),
                              Container(
                                width: 130,
                                height: 40,
                                alignment: Alignment.centerLeft,
                                child: Column(
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  children: [
                                    Container(
                                      alignment: Alignment.centerLeft,
                                      width: 130,
                                      height: 20,
                                      child: Text(
                                        "羚邦Medialink",
                                        style: TextStyle(
                                            color: Colors.white,
                                            fontWeight: FontWeight.w400),
                                      ),
                                    ),
                                    Container(
                                      alignment: Alignment.centerLeft,
                                      width: 130,
                                      height: 20,
                                      child: Text(
                                        "作品3",
                                        style: TextStyle(color: Colors.white70),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                          Container(
                            width: 98,
                            height: 40,
                            decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(50),
                                color: Color.fromRGBO(243, 224, 188, 1)),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Icon(
                                  Icons.album_outlined,
                                  size: 26,
                                  color: Colors.green,
                                ),

                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
                Padding(
                  padding: EdgeInsets.only(left: 10, right: 10),
                  child: Container(
                    width: MediaQuery.of(context).size.width,
                    height: 60,
                    child: Row(
                      mainAxisAlignment:
                      MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          "作品故事",
                          style: TextStyle(
                              fontSize: 25,
                              color: Colors.white,
                              fontWeight: FontWeight.w600),
                        ),
                        InkWell(
                          onTap: (){
                            Navigator.of(context).pushNamed("glbindex",arguments: threeMax);
                          },
                        child: Text(
                          "查看3D>   ",
                          style: TextStyle(
                              fontSize: 22,
                              color:
                              Colors.green,fontWeight: FontWeight.w600),
                        ),)
                      ],
                    ),
                  ),
                ),
                //图片
                Padding(
                  padding: EdgeInsets.only(left: 10, right: 10),
                  child: Container(
                    width: double.infinity,
                    height: 1700,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(30),
                      image: DecorationImage(
                          image: NetworkImage(toMap["productDescImage"].toString()),
                          fit: BoxFit.fill),
                    ),
                  ),
                ),
                Padding(
                    padding: EdgeInsets.only(left: 17, right: 17),
                    child: Container(
                      width: MediaQuery.of(context).size.width,
                      height: 30,
                      child: Row(
                        mainAxisAlignment:
                        MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "创作者",
                            style: TextStyle(
                                fontSize: 14,
                                color: Colors.white70),
                          ),
                          Text(
                            "安德鲁·德·圣埃克苏佩里基金会",
                            style: TextStyle(
                                fontSize: 14, color: Colors.white),
                          ),
                        ],
                      ),
                    )),
                Padding(
                    padding: EdgeInsets.only(left: 17, right: 17),
                    child: Container(
                      width: MediaQuery.of(context).size.width,
                      height: 30,
                      child: Row(
                        mainAxisAlignment:
                        MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "发行方",
                            style: TextStyle(
                                fontSize: 14,
                                color: Colors.white70),
                          ),
                          Text(
                            "丽邦文化创意投资有限公司",
                            style: TextStyle(
                                fontSize: 14, color: Colors.white),
                          ),
                        ],
                      ),
                    )),
                SizedBox(
                  height: 10,
                ),
                Container(
                  width: MediaQuery.of(context).size.width,
                  height: 60,
                  decoration: BoxDecoration(borderRadius: BorderRadius.only(topLeft: Radius.circular(15),topRight: Radius.circular(15)),color: Color.fromRGBO(12, 13, 13, 1),),

                  child: Center(child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Container(width: 80,height: 30,child: Image.network(mylUrl,fit: BoxFit.fill,),),
                      Text("提供技术支持",style: TextStyle(color: Colors.white70),),
                    ],),),
                ),
                Container(
                  width: MediaQuery.of(context).size.width,
                  height: 2,
                  color: Color.fromRGBO(12, 13, 13, 1),
                ),
                Container(
                  width: MediaQuery.of(context).size.width,
                  height: 10,
                  color: Color.fromRGBO(12, 13, 13, 1),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}